<?php
class isp_komplain_penugasan_model extends MY_Model {
	var $model = 'isp_komplain_penugasan';


function getApp()
	{
		$ls_sql	= "	SELECT	kode_status value,
							nama_status display
					FROM	ADMIN_PRIMKOKAS.ISP_KOMPLAIN_STATUS 
					ORDER BY kode_status";
					
		$result	= $this->db->query($ls_sql);
		if($result->num_rows() > 0){
			return $result->result_array();
		}else{
			return array();
		}
	}


	function GetJSON()
	{
		$ls_sql	= "	SELECT	d.id_komplain,
							a.id_penugasan,
							a.kode_komplain,
							TO_CHAR(a.tgl_komplain,'DD/MM/YYYY') tgl_komplain,
							a.nama,
							a.status,
							a.keterangan,
							TO_CHAR(a.tgl_selesai,'DD/MM/YYYY') tgl_selesai,b.nama_status,
							c.nama as nama_unit,d.komplain
					FROM	isp_komplain_penugasan a
					LEFT JOIN isp_komplain_status b ON a.status = b.kode_status
					LEFT JOIN 	isp_customer c ON a.kode_customer=c.kode_customer
					LEFT JOIN 	isp_komplain d ON a.kode_komplain=d.kode_komplain
					WHERE	(UPPER(a.kode_komplain) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.tgl_komplain) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.nama) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.status) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.tgl_selesai) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'id_penugasan' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order') );
					
		return json_encode( $this->paging($ls_sql) );
	}

	function GetJSON2()
	{
		$ls_sql	= "	SELECT	A.id_komplain,A.kode_komplain,TO_CHAR(A.tgl_komplain,'DD/MM/YYYY') tgl_komplain,A.kode_customer,A.komplain,A.status,A.keterangan,B.NAMA
					FROM	ISP_KOMPLAIN A
					LEFT JOIN 	ISP_CUSTOMER B ON A.KODE_CUSTOMER=B.KODE_CUSTOMER
					WHERE	(UPPER(A.kode_komplain) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(B.nama) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(A.komplain) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'A.kode_komplain' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
					
		return json_encode( $this->paging($ls_sql) );
	}
		
	function Add($arr_data){
		$this->db->insert('isp_komplain_penugasan', $arr_data);
	}
	
	function Update($arr_data, $arr_rule){
		$this->db->update('isp_komplain_penugasan', $arr_data, $arr_rule);
	}

	function UpdateStatus($arr_data, $arr_rule){
		$this->db->update('isp_komplain', $arr_data, $arr_rule);
	}
	
	function GetSingle($as_id_penugasan){
		$result = $this->db->get_where('isp_komplain_penugasan', array('id_penugasan' => $as_id_penugasan));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}
	
	function GetSingleView($as_id_penugasan)
	{
		$result = $this->db->get_where('isp_komplain_penugasan', array('id_penugasan' => $as_id_penugasan));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}

	function DeleteSingle($arr_rule)
	{
		try {
			if(	intval($this->get_data("SELECT COUNT(1) FROM isp_komplain_penugasan WHERE id_penugasan = '".$arr_rule['id_penugasan']."'"))<=0)
			{
				return $this->error_delete.' [Id: '.$arr_rule['id_penugasan']."]<br />";
			}else{
				$this->db->delete('isp_komplain_penugasan', array('id_penugasan' => $arr_rule['id_penugasan']));
				return '';
			}
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}
}
?>